package com.example.start.Interceptor;

import com.example.dmcommom.SpringBeanHelper;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		AuthenticationInterceptor authenticationInterceptor
                = SpringBeanHelper.getBeanOrThrow(AuthenticationInterceptor.class);
		RequestHeaderContextInterceptor requestHeaderContextInterceptor
                = SpringBeanHelper.getBeanOrThrow(RequestHeaderContextInterceptor.class);

		registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns("/**/error");
		// 拦截所有请求;跳过默认全局异常拦截器的转发
		registry.addInterceptor(requestHeaderContextInterceptor).addPathPatterns("/**").excludePathPatterns("/**/error");
	}

}